//
//  DeviceListEmptyTableCell.swift
//  SmartPenSwift
//
//  Created by tql on 2021/3/5.
//

import UIKit

class DeviceListEmptyTableCell: UITableViewCell {

    var state : Int32 = 0 {
        willSet{
            debugPrint("newValue === state \(newValue)")
            if newValue == 4 {
                self.retryBtn.setTitle("蓝牙没打开", for: .normal)
            }else if newValue == 0 {
                self.retryBtn.setTitle("重试", for: .normal)
            }
            
            let stringcontent : String = (self.retryBtn.titleLabel?.text)!
            
            var width : CGFloat = 100
            self.retryBtn.snp.makeConstraints { (make) in
                make.height.equalTo(50)
                make.width.equalTo(width)
                make.center.equalTo(self.contentView)
            }
            
        }
    }
    lazy var retryBtn : UIButton = {
        let btn : UIButton = UIButton.init()
        btn.setTitle("重试", for: .normal)
        btn.layer.cornerRadius = 10
        btn.backgroundColor = .black
        btn.addTarget(self, action: #selector(retrytAction(_ :)), for: .touchUpInside)
        return btn
    }()
    typealias callBackBlock = () -> ()
    var btnRetryBlock : callBackBlock?
    
    @objc func retrytAction(_ btn : UIButton){
        if self.btnRetryBlock != nil {
            self.btnRetryBlock!()
        }
    }
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        createUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func createUI() -> Void {
        self.contentView.addSubview(retryBtn)
        retryBtn.snp.makeConstraints { (make) in
            make.height.equalTo(50)
            make.center.equalTo(self.contentView)
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
